package com.example.ui.register.util;

import java.util.ArrayList;

import com.example.huashangapp.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SelectCityAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private ArrayList<City> list;

	public SelectCityAdapter(Context mContext, ArrayList<City> list) {
		inflater = LayoutInflater.from(mContext);
		this.list = list;
	}

	public ArrayList<City> getCcInfos() {
		return list;
	}

	public void setCcInfos(ArrayList<City> list) {
		this.list = list;
		if (list == null) {
			this.list = new ArrayList<City>();
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		View view;
		City c = list.get(position);
		if (convertView == null) {

			view = View.inflate(inflater.getContext(), R.layout.sc_item, null);
			holder = new Holder();
			holder.sc_city = (TextView) view.findViewById(R.id.si_city);
			view.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
			view = convertView;
		}

		holder.sc_city.setText(c.getCity());

		return view;
	}

	class Holder {
		TextView sc_city;
	}

}
